<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" value="" placeholder="请输入数字1" id="i1"> <br>
<input type="text" placeholder="请输入数字2" id="i2"> <br>
<button onclick="calc('+')">加</button>
<button onclick="calc('-')">减</button>
<button onclick="calc('*')">乘</button>
<button onclick="calc('/')">除</button>
<h4>运算结果: <span></span> </h4>
<script>
  function calc(op) {
    let i1 = document.getElementById('i1').value;
    let i2 = document.getElementById('i2').value;
    let span = document.querySelector('span');
    let result = 0;
    switch (op) {
      case '+':
        result = parseInt(i1) + parseInt(i2);
        break;
      case '-':
        result = parseInt(i1) - parseInt(i2);
        break;
      case '*':
        result = parseInt(i1) * parseInt(i2);
        break;
      case '/':
        if (i2 === '0') {
          alert('除数不能为0');
          return;
        }
        result = parseInt(i1) / parseInt(i2);
        break;
    }
    span.innerHTML=result;
  }
</script>
</body>
</html>